package fashionshop.dao;

import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;

import fashionshop.domain.Employee;
import fashionshop.util.HibernateUtil;

public class SystemDao {
	
	private static final Logger LOGGER = Logger.getLogger(SystemDao.class);
	
	public Employee employeeLogin(String username, String password){
		Session session = null;
		try{
			session = HibernateUtil.getSessionFactory().openSession();
			Query q = session.createQuery("from Employee where username = :username and password = :password");
			q.setString("username", username);
			q.setString("password", password);
			Object rsObj = q.uniqueResult();
			return rsObj != null ? (Employee)rsObj : null;
		}catch(Exception ex){
			LOGGER.error("Error in employeeLogin", ex);
			throw ex;
		}finally{
			session.close();
		}
	}

}
